extends Node2D
onready var MAIN = find_parent("MAIN")

# Called when the node enters the scene tree for the first time.
func _ready():
	$"PanelContainer/VBoxContainer/HBoxContainer/login".connect("pressed",self,"on_login")
	$"PanelContainer/VBoxContainer/HBoxContainer/back".connect("pressed",self,"on_back")
	pass # Replace with function body.

func on_login():
	var homeserver = $"PanelContainer/VBoxContainer/homeserver/edit".text
	var username = $"PanelContainer/VBoxContainer/username/edit".text
	var password = $"PanelContainer/VBoxContainer/password/edit".text
	MAIN.client.reset()
	MAIN.client.init_client(homeserver,username)
	var result = MAIN.client.login(password)
	if not result :
		$"PanelContainer/VBoxContainer/done".visible = false
		$"PanelContainer/VBoxContainer/error".visible = true
		return
	to_game()

func to_game():
	get_parent().activate()
	get_parent().visible = false
	MAIN.start_game()

func on_back():
	get_parent().activate()

# Called every frame. 'delta' is the elapsed time since the previous frame.
#func _process(delta):
#	pass
